import org.junit.Test;

/**
 * @作者 钟先崟
 * @时间 2023-01-18 17:11
 * @功能
 */
public class Solution
{
    public static void main(String[] args)
    {
        System.out.println(findMedianSortedArrays(new int[]{2, 2,4,4}, new int[]{2,2,4,4}));
    }
    public static double findMedianSortedArrays(int[] nums1, int[] nums2)
    {
        int[] nums3 = new int[nums1.length + nums2.length];
        int i1 = 0, i2 = 0, i3 = 0;
        for (; i3 < nums3.length; i3++)
        {
            if (i2 == nums2.length || (i1!=nums1.length && nums1[i1] < nums2[i2]))
            {
                nums3[i3] = nums1[i1];
                i1++;
            }
            else if (i1 == nums1.length || (i2!=nums2.length && nums1[i1] >= nums2[i2]))
            {
                nums3[i3] = nums2[i2];
                i2++;
            }
        }
        if (nums3.length % 2 == 0)
            return (nums3[nums3.length / 2 - 1] + nums3[nums3.length / 2]) * 1.0 / 2;
        return nums3[nums3.length / 2];
    }
}